const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'none',
  entry: {
    index: './src/main.js'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name]-[hash].bundle.js'
    // publicPath: '/dist',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      {
        enforce: 'pre',
        test: /\.(js|vue)$/,
        use: {
          loader: 'eslint-loader',
          options: {
            fix: true
          }
        },
        exclude: /node_modules/
      },
      {
        test: /\.vue?$/,
        loader: 'vue-loader',
        exclude: /node_modules/
      },
      {
        test: /\.less$/,
        use: [
          {
            loader: 'style-loader'
          },
          {
            loader: 'css-loader'
          },
          {
            loader: 'less-loader',
            options: {
              lessOptions: {
                strictMath: true
              }
            }
          }
        ]
      },
      {
        test: /\.(png|jpe?g|gif)$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10 * 1024,
            esModule: false
          }
        }
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      title: 'webpack Plugin Simple',
      meta: {
        viewport: 'with=device-width'
      },
      template: './public/index.html',
      filename: 'index.html',
      chunks: ['index']
    })

    // new webpack.DefinePlugin({
    //   // 值要求的是一个代码片段
    //   BASE_URL: JSON.stringify(HtmlWebpackPlugin.options.url)
    // })
  ]
}
